<%@ Control Language="C#" ClassName="_TableControl" Inherits="Dimok.Web.UI.TableControl" %>
<%@ Register Namespace="Dimok.Web.UI"  Assembly="Dimok.Web.UI" TagPrefix="OR"  %>

<asp:UpdatePanel ID="pnlBankAccount" UpdateMode="Always" runat="server">
	<ContentTemplate>
		<OR:GridViewEx ID="grv" runat="server" AutoGenerateColumns="False" DataSourceID="ds"
			ShowFooter="True" AllowSorting="True" BackColor="Window" CellPadding="0" EnableTheming="True"
			Font-Names="verdana" EnableViewState="False" DataKeyNames="ID"
			ViewNameUpdate="v_Update" ViewNameInsert="v_Insert"
			>
			<Columns>

				<asp:TemplateField HeaderText="ID" SortExpression="ID">
					<ItemStyle CssClass="rowBorder" />
					<ItemTemplate><asp:Label Text='<%#Eval("ID") %>' runat="server" />
					</ItemTemplate>
					<EditItemTemplate>
						<asp:TextBox ID="txtID" Text='<%# Bind("ID") %>' runat="server" />
					</EditItemTemplate>
					<FooterTemplate>
						<asp:TextBox ID="ID" Text='<%# Bind("ID") %>' cssclass="Streach" runat="server" />
					</FooterTemplate>
					<ControlStyle CssClass="GridTextBox" />
				</asp:TemplateField>

				<asp:TemplateField HeaderText="ParentID" SortExpression="ParentID">
					<ItemStyle CssClass="rowBorder" />
					<ItemTemplate><asp:Label Text='<%#Eval("ParentID") %>' runat="server" /></ItemTemplate>
					<EditItemTemplate><asp:TextBox ID="txtPArentID" Text='<%# Bind("ParentID") %>' runat="server" /></EditItemTemplate>
					<FooterTemplate><asp:TextBox ID="ParentID" Text='<%# Bind("ParentID") %>' cssclass="Streach" runat="server" /></FooterTemplate>
					<ControlStyle CssClass="GridTextBox" />
				</asp:TemplateField>

				<asp:TemplateField HeaderText="Type" SortExpression="TypeID">
					
					<ItemStyle CssClass="rowBorder" />
					<ItemTemplate><asp:Label Text='<%#Eval("TypeName") %>'  cssclass="GridTextBox" runat="server" /></ItemTemplate>
					<EditItemTemplate>
						<asp:DropDownList ID="selTypeID" DataSourceID="dsAcctType" DataTextField="Name" DataValueField="ID"
								 SelectedValue='<%# Bind("TypeID") %>' Style="font-size:x-small"
								 runat="server">
						</asp:DropDownList>
					</EditItemTemplate>
					<FooterTemplate>
						<asp:DropDownList ID="TypeID" DataSourceID="dsAcctType" DataTextField="Name" DataValueField="ID"
								 SelectedIndex='<%# -1 %>' CssClass="Streach"
								 runat="server">
						</asp:DropDownList>
					</FooterTemplate>
					<FooterStyle HorizontalAlign=Center />
					<ControlStyle CssClass="GridTextBox" />
				</asp:TemplateField>

				<asp:TemplateField HeaderText="Bank" SortExpression="Bank">
					
					<ItemStyle CssClass="rowBorder" />
					<ItemTemplate><asp:Label Text='<%#Eval("Bank") %>'  cssclass="GridTextBox" runat="server" /></ItemTemplate>
					<EditItemTemplate>
						<asp:DropDownList ID="selBankID" DataSourceID="dsBanks" DataTextField="Name" DataValueField="ID"
								 SelectedValue='<%# Bind("BankID") %>' Style="font-size:85%"
								 runat="server">
						</asp:DropDownList>
					</EditItemTemplate>
					<FooterTemplate>
						<asp:DropDownList ID="BankID" DataSourceID="dsBanks" DataTextField="Name" DataValueField="ID"
								 SelectedIndex='<%# -1 %>' CssClass="Streach"
								 runat="server">
						</asp:DropDownList>
					</FooterTemplate>
					<FooterStyle HorizontalAlign=Center />
					<ControlStyle CssClass="GridTextBox" />
				</asp:TemplateField>

				<asp:TemplateField HeaderText="Name" SortExpression="Name">
					<ItemStyle CssClass="rowBorder" />
					<ItemTemplate><asp:Label Text='<%#Eval("Name") %>' runat="server" /></ItemTemplate>
					<EditItemTemplate><asp:TextBox ID="txtName" Text='<%# Bind("Name") %>' runat="server" /></EditItemTemplate>
					<FooterTemplate><asp:TextBox ID="Name" Text='<%# Bind("Name") %>' cssclass="Streach" runat="server" /></FooterTemplate>
					<FooterStyle HorizontalAlign=Center />
					<ControlStyle CssClass="GridTextBox" />
				</asp:TemplateField>

				<asp:BoundField DataField="Balance" HeaderText="Balance" SortExpression="Balance"
						 HeaderStyle-CssClass="raised"
						 ItemStyle-CssClass="rowBorder"
				/>
			</Columns>
		</OR:GridViewEx>
	</ContentTemplate>
</asp:UpdatePanel>
<asp:SqlDataSource ID="ds" runat="server"
	SelectCommand=
	"IF EXISTS(SELECT * FROM v_Select)
		SELECT ba.ID, ba.ParentID, ba.TypeID, ba.BankID, b.Name Bank, ba.Name,bat.Name TypeName, ba.Description, ba.Balance FROM t_BankAccount ba
		INNER JOIN ts_BankAccountType bat ON bat.ID = ba.TypeID
		LEFT OUTER JOIN t_Bank b ON ba.BankID = b.ID
	 ELSE
		SELECT ''ID, ''ParentID, ''TypeID, ''BankID, '' Bank, ''Name,''TypeName, ''Description, ''Balance
	"
	UpdateCommand="PRINT ''"
	DeleteCommand="DELETE FROM t_TableDelete WHERE ID = @ID"
>
	<SelectParameters>
		<asp:Parameter Name="ID" Type="string" DefaultValue="0" />
	</SelectParameters>
	<DeleteParameters>
		<asp:Parameter Name="ID" Type="string" />
	</DeleteParameters>
	<UpdateParameters>
		<asp:Parameter Name="ID" Type="string" />
		<asp:Parameter Name="ParentID" Type="string" />
		<asp:Parameter Name="TypeID" Type="Int32" />
		<asp:Parameter Name="BankID" Type="Int32" />
		<asp:Parameter Name="Name" Type="String" />
		<asp:Parameter Name="Description" Type="String" />
		<asp:Parameter Name="Balance" Type="Decimal" />
	</UpdateParameters>
</asp:SqlDataSource>

<asp:SqlDataSource ID="dsLookUp" runat="server"
	SelectCommand="SELECT [ID], [Name] FROM [ts_TableLookUp] ORDER BY [Name]"
></asp:SqlDataSource>
